package cs.oor;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class ConfigActivity extends Activity {

    
    protected SharedPreferences settings;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.config);
        
        SharedPreferences settings = this.getSettings();
        
        final EditText login = (EditText) findViewById(R.id.oxidLogin);
        login.setText(settings.getString(Config.SHOP_LOGIN, ""));
            
        final EditText pwd = (EditText) findViewById(R.id.oxidPwd);
        pwd.setText(settings.getString(Config.SHOP_PWD, ""));
        
        final EditText url = (EditText) findViewById(R.id.oxidUrl);
        url.setText(settings.getString(Config.SHOP_URL, ""));
        
    }
    
    public void saveSettings(View Button) {
        EditText login = (EditText) findViewById(R.id.oxidLogin);
        String userLogin = login.getText().toString();
        
        EditText pwd = (EditText) findViewById(R.id.oxidPwd);
        String userPwd = pwd.getText().toString();
        
        EditText url = (EditText) findViewById(R.id.oxidUrl);
        String shopUrl = url.getText().toString();
        
        SharedPreferences settings = this.getSettings();
        
        SharedPreferences.Editor editor = settings.edit();
        
        editor.putString(Config.SHOP_LOGIN, userLogin);
        editor.putString(Config.SHOP_PWD, userPwd);
        editor.putString(Config.SHOP_URL, shopUrl);
        
        editor.commit();
    }
    
    public SharedPreferences getSettings() {
        if (this.settings == null) {
            SharedPreferences settings = getSharedPreferences(Config.PREFS_NAME, 0);
            
            this.settings = settings;
        }
        
        return this.settings;
    }
}